package com.zhan.easyexcelorder.model;

import com.alibaba.fastjson.annotation.JSONField;
import com.zhan.jpa.model.BaseEntity;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.Where;
import org.hibernate.annotations.Cache;

import javax.persistence.*;
import java.util.List;

@Entity
@Table(name = "sys_department")
@Cacheable
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE, region = "entityCache")
@Getter
@Setter
public class SysDepartment extends BaseEntity implements java.io.Serializable {
    private static final long serialVersionUID = 436177582631250154L;

    @ApiModelProperty("部门名称")
    private String deptName;
    @ApiModelProperty("部门全称")
    private String fullDepartmentName;
    @ApiModelProperty("部门等级")
    private Integer deptLevel;
    @ApiModelProperty("部门描述")
    private String deptDescription;
    @ApiModelProperty("排序字段")
    private Integer sortCount;
    @ApiModelProperty(value = "状态（0-有效，1-无效）", allowableValues = "0,1", hidden = true)
    private Integer state = 0;

//    @Transient
//    private Boolean checked=false;

    @JSONField(serialize = false)
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "parent_id")
    private SysDepartment parent;

    @OneToMany(fetch = FetchType.LAZY, mappedBy = "parent")
    @Where(clause = "is_delete=0")
    @OrderBy("sortCount asc")
    List<SysDepartment> children;

}
